﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DBManager.Download
{
    public class DownloadDAL
    {
        public static DataTable GetListDownload(string search,string PageSize, string PageIndex)
        {
            int IndexSize = int.Parse(PageSize) * int.Parse(PageIndex);
            string sql = @"SELECT  * 
		    FROM 
		    ( 
			SELECT TOP(" + IndexSize + @") 
				dl.TypeProduct,pd.Avatar,pd.Title,pd.id,pd.Url,dl.DownloadID,dl.LinkDownload,DistributionDate,dl.Title as Name,
				ROW_NUMBER() OVER (ORDER BY pd.Title ASC ) Row	
            From	 
			DownloadProduct dl 
            inner join Products pd on dl.id=pd.id  
			WHERE dl.Status=1 and pd.Title like N'%" + search + "%' or dl.Title like N'%" + search + @"%' 
		) dl 
		WHERE   ROW Between (" + comm.to_sqlnumber(PageIndex) + " -1)*" + comm.to_sqlnumber(PageSize) + " + 1 AND " + IndexSize + "";
            return DBUtil.SelectTable(sql);
        }
        public static DataTable CountGetListDownload(string search)
        {
            string sql = @"
			SELECT count(*) as TongBanGhi
            From	 
			DownloadProduct dl 
            inner join Products pd on dl.id=pd.id  
			WHERE dl.Status=1 and pd.Title like N'%" + search + "%' or dl.Title like N'%" + search + @"%' ";
            return DBUtil.SelectTable(sql);
        }
    }
}
